package com.sinaapp.gavinzhang.third;

import org.junit.Test;

/**
 * 利用数码管显示数字
 * Created by gavin on 15-8-8.
 */
public class NumberShow {

    @Test
    public void showNum()
    {
        //待显示数字
        int i = 65432;
        //数码管数字对应字符
        char[] num = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};

        //创建显示数组
        char[] show = new char[5];

        //显示
        int tmp =i;
        for (int j = 0; j < 5; j++) {
            show[j] = num[tmp%10];
            tmp /= 10;
        }

        //依靠显示数组取得原数
        tmp = 0;
        for (int j = 4; j >=0; j--) {
            for (int k = 0; k < 10; k++) {
                if (num[k]==show[j])
                {
                    tmp = tmp*10+k;
                }
            }
        }
        System.out.println(tmp);
    }
}
